/*global module:false*/
module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        // Metadata.
        pkg: grunt.file.readJSON('package.json'),
        banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
            '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
            '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
            '* Copyright (c) <%= grunt.template.today("yyyy") %>' +
            ' Licensed <%= pkg.licenses[0].type%> */\n' +
            '(function(window,document){\n' +
            'var VERSION="<%=pkg.version%>";\n',
        //'"use strict";\n',
        // Task configuration.
        footer: '\n})(window,document);',
        testPlgin: 'var VERSION="<%=pkg.version%>";\n',
        concat: {
            all: {
                options: {
                    banner: '<%= banner %>',
                    footer: '<%=footer%>'
                },
                src: ['src/prepare.js', 'src/tempHelper.js', 'src/*.js'],
                dest: 'pub/<%= pkg.name %>.js'
            },
            test: {
                options: {
                    banner: '<%=testPlgin%>'
                },
                src: ['src/prepare.js', 'src/tempHelper.js', 'src/*.js'],
                dest: 'pub/<%= pkg.name %>_dev.js'
            }
        },
        uglify: {
            dist: {
                src: 'pub/<%= pkg.name %>.js',
                dest: 'pub/<%= pkg.name %>.min.js'
            }
        },
        jshint: {
            options: {
                "globals": {
                    "jQuery": true
                },
                '-W033': true,
                '-W084': true,
                '-W083': true,
                '-W041': true,
                '-W030': true
            },

            beforeconcat: ['src/*.js'],
            afterconcat: ['pub/*.js', '!pub/*.min.js'],
            test: ['test/*.js'],
            aftertest: ['pub/*.js', '!<%uglify.dist.dest%>']

        },
        jasmine: {
            defualt: {
                src: 'pub/*_dev.js',
                options: {
                    vendor: [
                        "libs/jquery-1.11.0.js",
                        "libs/jasmine-jquery.js",
                        "libs/mock-ajax.js",
                        "libs/jqueryAjaxTestHelper.js"
                    ],
                    keepRunner: false,
                    specs: 'test/*Spec.js'
                }
            },
            temp: {
                src: 'pub/<%= pkg.name %>_dev.js',
                options: {
                    vendor: [
                        "libs/jquery-1.11.0.js",
                        "libs/jasmine-jquery.js",
                        "libs/mock-ajax.js",
                        "libs/jqueryAjaxTestHelper.js"
                    ],
                    keepRunner: true,
                    specs: 'test/watchDataChangeSpec.js'
                }
            }
        },
        watch: {
            scripts: {
                files: ['src/*.js', 'test/*.js'],
                tasks: ['test', 'concats'],
                options: {
                    spawn: false,
                    interrupt: true
                }
            },
            doc: {
                files: ["src/*.js"],
                tasks: ["doc"],
                options: {
                    spawn: false,
                    interrupt: true
                }
            }
        },
        jsdoc: {
            dist: {
                src: ['src/*.js'],
                dest: 'doc',
                options: {
                    encoding: "utf8"
                }
            }
        }


    });
    // These plugins provide necessary tasks.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-jasmine');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-jsdoc');
    // Default task., 'jshint:afterconcat'  'jshint:beforeconcat',
    grunt.registerTask('concats', ['concat:all', 'jshint:afterconcat']);
    //grunt.registerTask('contest', ['concat:test', 'jshint:afterconcat'])
    grunt.registerTask('test', ['concat:test', 'jshint:test', 'jasmine:defualt']);
    grunt.registerTask('pub', ['jshint:beforeconcat', 'concat:test', 'concat:all', 'jshint:afterconcat', 'jshint:test', 'jasmine:defualt', 'uglify:dist']);

    grunt.registerTask('watchCode', ['watch:scripts'])
    //Doc
    // grunt.registerTask('yuidocs', ['yuidoc'])
    grunt.registerTask('doc', ['jsdoc:dist'])
    grunt.registerTask('watchDoc', ['watch:doc'])

    //Temp test
    grunt.registerTask('default', ['concat:test', 'jshint:afterconcat', 'jasmine:temp']);

};